import {AbilityModel} from "../../controller/model/AbilityModel";
import Configer from "../../frame/apiModel/config/Configer";
import {FinalKey} from "../../constant/FinalConstant";
import {UnitController} from "../../controller/UnitController";
import {Logger} from "../../frame/apiModel/config/Logger";
import {UnitModel} from "../../frame/apiModel/adapterModel/model3/UnitModel";
import {ItemModel} from "../../frame/apiModel/adapterModel/model3/ItemModel";
import {PlayerModel} from "../../frame/apiModel/adapterModel/model4/PlayerModel";
import {LocModel} from "../../frame/apiModel/base/LocModel";
import {PlayerFactory} from "../../frame/PlayerFactory";
import {DataRouterUtil} from "../../utils/router/DataRouterUtil";
import {CodeUtil} from "../../frame/codeAdapter/CodeUtil";
import {AttributeEnum} from "../../frame/dataSource/DataModel";
import {Util} from "../../utils/Util";
import {AbilityUtil} from "./AbilityUtil";

export default class ReleasePetSkillModel extends AbilityModel {
    abilityId: string = Configer.getFinal(FinalKey.releasePetAbilityId) as string;

    actionFun = (activeUnit: UnitModel, activeItem: ItemModel, targetUnit: UnitModel, targetItem: ItemModel, activePlayer: PlayerModel, targetPlayer: PlayerModel, spellId: string, spellLoc: LocModel)  => {
        let success = true;
        const index = UnitController.getInstance().getPetIndex(targetUnit, activePlayer);
        if (index >= 0) {
            const activePlayerId = activePlayer.playerId;
            const targetPlayerId = targetPlayer.playerId;
            if (activePlayerId === targetPlayerId) {
                success = UnitController.getInstance().releasePet(activePlayer, index);
            } else {
                Logger.toastProduct('不能放生别人的单位！', activePlayer)
                return;
            }
        } else {
            Logger.toastError('只能放生宠物');
            success = false;
        }
        return success;
    }
}